<template>
    <div class="qingwu">
        <div class="admin_table_page_title">闲置商品管理</div>
        <div class="unline underm"></div>

        <estate-search :searchConfig="searchConfig" @searchParams="search"></estate-search>

        <div class="admin_table_handle_btn">
        </div>
        <div class="admin_table_list">
            <a-table :columns="columns" :data-source="list" :pagination="false" :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" row-key="id">
                <span slot="name" slot-scope="rows">
                    <div class="admin_goods_pic_txt">
                        <div class="img"><img v-if="rows.goods_images[0]" :src="rows.goods_images[0]"><a-icon v-else type="picture" /></div>
                        <div class="block">
                            <div class="text" :title="rows.goods_name">{{rows.goods_name}}</div>

                        </div>

                        <div class="clear"></div>
                    </div>
                </span>

                <span slot="action" slot-scope="rows">
                    <a-button icon="edit" @click="$router.push('/Estate/flea_goods/form/'+rows.id)">查看</a-button>
                    <a-button type="danger" icon="delete" @click="del(rows.id)">删除</a-button>
                </span>
            </a-table>
            <div class="admin_pagination" v-if="total>0">
                <a-pagination v-model="params.page" :page-size.sync="params.per_page" :total="total" @change="onChange" show-less-items />
            </div>

            <a-modal v-model="visible" title="删除原因" @ok="handleOk">
                <textarea name="refuse_info" cols="75" rows="3" v-model="refuse_info"></textarea>
            </a-modal>
        </div>
    </div>
</template>

<script>
import estateSearch from '@/components/estate/search'
export default {
    components: {estateSearch,},
    props: {},
    data() {
      return {
          id:null,
          refuse_info:'',
          visible: false,
          params:{
              page:1,
              per_page:30,
          },
          total:0, //总页数
          searchConfig:[
              {label:'商品名称',name:'goods_name',type:'text'},
              {label:'小区',name:'community_id',type:'select',data:[]},
              {label:'商品分类',name:'cate_id',type:'select',data:[]},
          ],
          selectedRowKeys:[], // 被选择的行
          columns:[
              {title:'商品名称',key:'id',scopedSlots: { customRender: 'name' }},
              {title:'价格',dataIndex:'goods_price'},
              {title:'交易方式',dataIndex:'type_text'},
              {title:'分类',dataIndex:'cate_name'},
              {title:'创建时间',dataIndex:'created_at'},
              {title:'操作',key:'id',scopedSlots: { customRender: 'action' }},
          ],
          list:[],
          list2:[],
          count:[],
      };
    },
    watch: {},
    computed: {},
    methods: {
        search(params){
            let page = this.params.page;
            let per_page = this.params.per_page;
            this.params = params;
            this.params.page = page;
            this.params.per_page = per_page;
            this.onload();
        },
        // 选择框被点击
        onSelectChange(selectedRowKeys) {
            this.selectedRowKeys = selectedRowKeys;
        },
        // 删除
        del(id){
            if(!id){
                return this.$message.error('未选择数据.');
            }
            this.id = id
            this.visible = true;

            /*this.$confirm({
                title: '你确定要删除选择的数据？',
                content: '<input>',
                okText: '是',
                okType: 'danger',
                cancelText: '取消',
                onOk:()=> {
                    this.$delete(this.$api.fleaGoods+'/'+id).then(res=>{
                        if(res.code == 200){
                            this.onload();
                            this.$message.success('删除成功');
                        }else{
                            this.$message.error(res.msg)
                        }
                    });

                },
            });*/
        },
        handleOk(e) {
            if(this.$isEmpty(this.refuse_info)){
                return this.$message.error('请填写删除原因');
            }
            let param = this.id + '&'+this.refuse_info
            this.$delete(this.$api.fleaGoods+'/'+param).then(res=>{
                if(res.code == 200){
                    this.onload();
                    this.$message.success('删除成功');
                    this.visible = false;
                }else{
                    this.$message.error(res.msg)
                }
            });
        },
        onload(){
            this.$get(this.$api.fleaGoods,this.params).then(res=>{
                this.list = res.data.data;
                this.count = res.data.count;
                this.total = res.data.total;
            });
            //获取小区列表
            this.$get(this.$api.estateCommunity).then(res=>{
                let com_data = res.data.data;
                let list = []
                com_data.forEach(v=>{
                    list.push({label:v.community_name,value:v.community_id})
                })
                this.$set( this.searchConfig[1],'data',list)

            });
            //获取分类列表
            this.$get(this.$api.estateGoodsClasses).then(res=>{
                let cate_data = res.data;
                let list2 = []
                cate_data.forEach(v=>{
                    list2.push({label:v.name,value:v.id})
                })
                // console.log(this.searchConfig[2])
                // console.log(list2)
                this.$set( this.searchConfig[2],'data',list2)
                // console.log(this.searchConfig[2])
            });
        },
        to_nav(e){
            this.params.goods_verify = e;
            this.params.page = 1;
            this.onload();
        },
    },
    created() {
        this.onload();
    },
    mounted() {}
};
</script>
<style lang="scss" scoped>

</style>
